<template>
  <div class="app-container">
    <el-row class="row-spacing">
      <el-col :span="24" :xs="24">
        <div class="top-right-btn" :style="style">
          <el-tooltip class="item" effect="dark" content="刷新" placement="top">
            <el-button size="mini" circle icon="el-icon-refresh" @click="refresh()" />
          </el-tooltip>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-table v-loading="loading" :data="userList" >
          <el-table-column label="ERP物料号"  prop="materialNum" width="120"/>
          <el-table-column label="物料名称" prop="materialName" min-width="170"   />
          <el-table-column label="是否本安" align="center" prop="isSafe" width="80">
            <template slot-scope="scope">
              <span>{{scope.row.isSafe ? '是':'否'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="协议类型" align="center" prop="protocolType" width="100">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.mc_protocol_type"
                :value="scope.row.protocolType"
              />
            </template>
          </el-table-column>
          <el-table-column label="规格型号" align="center" prop="materialSpecs"    />
          <el-table-column label="ERP软件版本编码" align="center" prop="softVerCode"  />
          <el-table-column label="ERP软件版本名称" align="center" prop="softVerName"  >
            <template slot-scope="scope">
              <div style="white-space: pre-line;">{{ scope.row.softVerName }}</div>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" prop="materialRemark"  width="100"/>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope" >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['mc:material:mgr']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['mc:material:mgr']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>

import { delMaterial, listAllMaterial, updateMaterial } from '@/api/material/material'

export default {
  name: "MaterialHideMgr",
  dicts: ['mc_protocol_type', 'mc_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        materialNum: undefined,
        materialName: undefined,
        materialSpecs:undefined,
        materialType: 100,
        isSafe: undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listAllMaterial(this.queryParams).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    refresh(){
      this.getList();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$modal.confirm('是否确认设置物料号为"' + row.materialNum + '"的数据项为显示状态').then(function() {
        return updateMaterial({ id: row.id, hideFlag: '0', isEmail: '0'});
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("修改成功");
      }).catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const materialId = row.id;
      this.$modal.confirm('是否确认删除物料号为"' + row.materialNum + '"的数据项？').then(function() {
        return delMaterial(materialId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
<style lang="scss" scoped>
.row-spacing {
  margin-bottom: 20px;
}
</style>
